<template>
  <!-- 商品列表 -->
  <div>
    <!-- 顶部 -->
    <div id="top">
      <span class="iconfont arrow_l">&#xe603;</span>
      <h2>小U商城</h2>
      <p>
        <span class="iconfont">&#xe64a;</span>
        <span class="iconfont">&#xe614;</span>
        <i class="line"></i>
      </p>
    </div>
    <!-- 头部搜索框 -->
    <header>
      <input
        type="text"
        name="usename"
        placeholder="按内容搜索"
        v-model="msg"
      />
      <i class="iconfont">&#xe626;</i>
    </header>
    <div id="nav">
      <nav>
        <a href="#" class="cur">综合推荐</a>
        <a href="#">销量<i class="iconfont">&#xe601;</i></a>
        <a href="#">价格</a>
        <a href="#">好评度</a>
        <a href="#">店铺</a>
      </nav>
      <p><span class="iconfont">&#xe637;&ensp;</span>筛选</p>
    </div>
    <!-- 提示 -->
    <div id="screen">
      <input type="text" value="筛选11.11大促商品" />
    </div>
    <div id="Goods" v-show="list.length > 0">
      <div
        class="box1"
        v-for="item in list"
        :key="item.id"
        @click="godetail(item.id)"
      >
        <div class="left">
          <img :src="$pre + item.img" alt="" />
        </div>
        <div class="right">
          <p class="p1">{{ item.goodsname }}</p>
          <p class="p2">敏感肌可用，控油祛痘、男女可用...</p>
          <p class="p3">
            <em>￥</em><span>{{ item.price }}</span
            ><del>￥{{ item.market_price }}</del>
            <i>999人已付款</i>
          </p>
          <p class="p4">11.11限时299元起</p>
          <p class="p5">
            <b>999条评论</b>
            <strong>99.9%好评</strong>
          </p>
        </div>
      </div>
    </div>
    <div id="last">
      <p></p>
    </div>
    <van-empty description="暂时无货" v-show="list.length <= 0" />
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import { search, getGoodlist } from "../../utils/api";
export default {
  props: [],
  components: {},
  data() {
    return {
      msg: "",
      list: [],
    };
  },
  watch: {
    msg() {
      search({ keywords: this.msg }).then((res) => {
        //console.log(res,111);
        this.list = res.data.list ? res.data.list : [];
      });
    },
  },
  computed: {
    ...mapGetters({}),
  },
  methods: {
    ...mapActions({}),
    godetail(id) {
      this.$router.push("/detail?id=" + id);
    },
  },
  mounted() {
    if (this.$route.query.id) {
      getGoodlist({
        cateid: this.$route.query.id,
        type: this.$route.query.type,
      }).then((res) => {
        //console.log(res);
        this.list = res.data.list.goodData ? res.data.list.goodData : [];
      });
    }
  },
};
</script>

<style scoped>
body,
html {
  height: 100%;
}
body {
  display: flex;
  flex-direction: column;
  max-width: 7.5rem;
  margin: 0 auto;
}
#top {
  height: 0.64rem;
  background: #ff6040;
  display: flex;
  padding: 0.28rem 0.12rem 0.28rem 0.32rem;
  color: #ffdfd8;
  align-items: center;
}
#top h2 {
  margin: 0 1.23rem 0 2.53rem;
  font-size: 0.32rem;
}
#top .arrow_l {
  font-size: 0.34rem;
}
#top p {
  width: 1.74rem;
  height: 0.64rem;
  border: 1px solid #ff8a6f;
  box-sizing: border-box;
  border-radius: 0.54rem;
  display: flex;
  align-items: center;
  position: relative;
}
#top p span {
  width: 50%;
  height: 100%;
  text-align: center;
  line-height: 0.64rem;
}
#top p .line {
  width: 1px;
  height: 0.37rem;
  background: #ff896e;
  position: absolute;
  top: 0.12rem;
  left: 0.86rem;
}
header {
  height: 1.15rem;
  background: #ff6648;
  color: #ffdfd8;
  position: relative;
}
header input {
  width: 7.1rem;
  height: 0.65rem;
  border: 0.02rem solid #e6e6e6;
  border-radius: 0.05rem;
  box-sizing: border-box;
  font-size: 0.26rem;
  color: #999;
  margin: 0.34rem 0.2rem 0.2rem 0.2rem;
  padding-left: 0.5rem;
}
header i.iconfont {
  font-size: 0.32rem;
  color: #999;
  vertical-align: top;
  position: absolute;
  left: 0.3rem;
  top: 0.5rem;
}
#nav {
  height: 0.76rem;
  background: #ff725b;
  display: flex;
  padding-top: 0.18rem;
  margin-top: -0.15rem;
  box-sizing: border-box;
}
#nav nav {
  width: 6.2rem;
  font-size: 0.26rem;
  padding: 0.05rem 0.15rem 0 0.2rem;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  height: 0.58rem;
  background: url(../../assets/img/line.jpg) no-repeat right top;
}
#nav nav a {
  color: #fff3f2;
}
#nav nav a.cur {
  font-weight: bold;
  position: relative;
  font-size: 0.3rem;
  margin-top: -0.04rem;
}
#nav p {
  width: 1.3rem;
  text-align: center;
  color: #fff3f2;
  padding-top: 0.05rem;
}
#nav p span {
  vertical-align: middle;
}
#screen {
  margin: 0.2rem 0.2rem 0 0.2rem;
  width: 7.06rem;
  height: 0.61rem;
}
#screen input {
  width: 7.06rem;
  height: 0.61rem;
  border-radius: 0.03rem;
  background: #fff4f2;
  color: #ff6040;
  font-weight: bold;
  font-size: 0.3rem;
  text-align: center;
  line-height: 0.61rem;
  border: 0.01rem solid #ff6040;
}
#Goods {
  width: 7rem;
  margin: 0.4rem 0.2rem 0 0.2rem;
  background: #fff;
  padding-bottom: 0.1rem;
}
#Goods .box1 {
  width: 7rem;
  height: 2.18rem;
  margin-bottom: 0.4rem;
  padding: 0.2rem 0 0.2rem 0;
  border-bottom: 1px solid #ccc;
}
#Goods .box1 .left {
  float: left;
  width: 2.16rem;
  height: 1.18rem;
  margin-right: 0.3rem;
}
#Goods .box1 .left img {
  width: 100%;
}
#Goods .box1 .right {
  float: left;
  width: 4.54rem;
  padding-top: 0.03rem 0 0.04rem 0;
  box-sizing: border-box;
}
#Goods .box1 .right .p1 {
  color: #333;
  font-size: 0.28rem;
  text-align: left;
  line-height: 0.3rem;
  margin-bottom: 0.12rem;
}
#Goods .box1 .right .p2 {
  color: #999;
  font-size: 0.26rem;
  text-align: left;
  line-height: 0.28rem;
  margin-bottom: 0.32rem;
}
#Goods .box1 .right .p3 {
  margin-bottom: 0.1rem;
}
#Goods .box1 .right .p3 em {
  color: #ff6040;
  font-size: 0.14rem;
  text-align: left;
  margin-right: 0.05rem;
  font-weight: bold;
}
#Goods .box1 .right .p3 span {
  font-size: 0.3rem;
  color: #ff6040;
  font-weight: bold;
  margin-right: 0.08rem;
}
#Goods .box1 .right .p3 del {
  font-size: 0.14rem;
  color: #999;
  font-weight: bold;
  margin-right: 0.21rem;
}
#Goods .box1 .right .p3 i {
  font-size: 0.18rem;
  color: #999;
}
#Goods .box1 .right .p4 {
  width: 1.68rem;
  height: 0.32rem;
  background: #ff8066;
  color: #fff;
  font-size: 0.16rem;
  text-align: center;
  line-height: 0.32rem;
  margin-bottom: 0.2rem;
}
#Goods .box1 .right .p5 b {
  font-size: 0.18rem;
  color: #999;
  margin-right: 0.22rem;
}
#Goods .box1 .right .p5 strong {
  font-size: 0.18rem;
  color: #999;
}
#last p {
  background-color: #000;
  border-radius: 0.4rem;
  width: 2.68rem;
  height: 0.1rem;
  margin-left: 2.41rem;
  position: fixed;
  bottom: 0.16rem;
}
</style>